import React, { Component } from 'react';
import { Router, Route, hashHistory, IndexRedirect } from 'react-router';
import App from '../App';
import Page from '../components/Page';
import Index from '../components/Index';
import Login from '../components/pages/Login';
// user
import UserList from '../components/user/List';
import UserInfo from '../components/user/Info';
// order
import OrderList from '../components/order/List';
import OrderInfo from '../components/order/Info';
//
import CashList from '../components/cash/List';
// other
import Error404 from '../components/pages/Error404';

/*const Wysiwyg = (location, cb) => {     // 按需加载富文本配置
    require.ensure([], require => {
        cb(null, require('../components/ui/Wysiwyg').default);
    }, 'Wysiwyg');
};*/
import { LocaleProvider } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';

export default class CRouter extends Component {
    requireAuth = (permission, component) => {
        const { store } = this.props;
        const { auth } = store.getState().httpData;
        if (!auth || !auth.data.permissions.includes(permission)) window.location.hash = '/404';
        return component;
    };
    render() {
        return (
            <LocaleProvider locale={zhCN}>
                <Router history={hashHistory}>
                    <Route path={'/'} components={Page}>
                        <IndexRedirect to="/app/index" />
                        <Route path={'app'} component={App}>
                            <Route path={'index'} component={Index} />
                            <Route path={'user'}>
                                <Route path={'list'} component={UserList} />
                                <Route path={'info/:uid'} component={UserInfo} />
                            </Route>
                            <Route path={'order'}>
                                <Route path={'list'} component={OrderList} />
                                <Route path={'info/:oid'} component={OrderInfo} />
                            </Route>
                            <Route path={'cash'}>
                                <Route path={'list'} component={CashList} />
                            </Route>
                            <Route path={'*'} component={Error404} />
                        </Route>
                    </Route>
                    <Route path={'login'} component={Login} />
                </Router>
            </LocaleProvider>
        )
    }
}
